home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 August (Alt) / CHIP 2005-08.1.iso / program / guvenlik / syslinux-3.07.exe / sample / filetest.c < prev    next >
Encoding:
C/C++ Source or Header  |  2005-01-03  |  2.4 KB  |  99 lines

  1. #include <com32.h>
  2. #include <stdarg.h>
  3.  
  4. #define NULL ((void *)0)
  5. int printf(const char *, ...);
  6. int putchar(int);
  7.  
  8. static inline void memset(void *buf, int ch, unsigned int len)
  9. {
  10.   asm volatile("cld; rep; stosb"
  11.                : "+D" (buf), "+c" (len) : "a" (ch) : "memory");
  12. }
  13.  
  14. static void strcpy(char *dst, const char *src)
  15. {
  16.   while ( *src )
  17.     *dst++ = *src++;
  18.  
  19.   *dst = '\0';
  20. }
  21.  
  22. static void printregs(const com32sys_t *r)
  23. {
  24.   printf("eflags = %08x  ds = %04x  es = %04x  fs = %04x  gs = %04x\n"
  25.      "eax = %08x  ebx = %08x  ecx = %08x  edx = %08x\n"
  26.      "ebp = %08x  esi = %08x  edi = %08x  esp = %08x\n",
  27.      r->eflags.l, r->ds, r->es, r->fs, r->gs,
  28.      r->eax.l, r->ebx.l, r->ecx.l, r->edx.l,
  29.      r->ebp.l, r->esi.l, r->edi.l, r->_unused.l);
  30. }
  31.  
  32. int __start(void)
  33. {
  34.   unsigned int ax,cx,si,t;
  35.   com32sys_t  inreg,outreg;
  36.   char *p;
  37.   
  38.   /* Test null system call */
  39.   inreg.eflags.l = 0xffffffff;
  40.   inreg.eax.l = 0x11110000;
  41.   inreg.ecx.l = 0x22222222;
  42.   inreg.edx.l = 0x33333333;
  43.   inreg.ebx.l = 0x44444444;
  44.   inreg.ebp.l = 0x55555555;
  45.   inreg.esi.l = 0x66666666;
  46.   inreg.edi.l = 0x77777777;
  47.   inreg.ds = 0xaaaa;
  48.   inreg.es = 0xbbbb;
  49.   inreg.fs = 0xcccc;
  50.   inreg.gs = 0xdddd;
  51.   printregs(&inreg);
  52.   __com32.cs_intcall(0x22, &inreg, &outreg);
  53.   printregs(&outreg);
  54.   printf("----\n");
  55.  
  56.   memset(&inreg, 0, sizeof inreg);
  57.   memset(&outreg, 0, sizeof outreg);
  58.   strcpy(__com32.cs_bounce, "test.txt");
  59.   inreg.eax.w[0] = 0x0006;  // Open file
  60.   inreg.esi.w[0] = OFFS(__com32.cs_bounce);
  61.   inreg.es = SEG(__com32.cs_bounce);
  62.   printregs(&inreg);
  63.   __com32.cs_intcall(0x22, &inreg, &outreg);
  64.   printregs(&outreg);
  65.   printf("----\n");
  66.   
  67.   si = outreg.esi.w[0];        /* File handle */
  68.   cx = outreg.ecx.w[0];        /* Block size */
  69.   ax = outreg.eax.l;        /* File length */
  70.  
  71.   while ( si ) {
  72.     /* We can only read 64K per call */
  73.     t = ( ax > 65536 ) ? 65536/cx : (ax+cx-1)/cx;
  74.     
  75.     memset(&inreg, 0, sizeof inreg);
  76.     inreg.esi.w[0] = si;
  77.     inreg.ecx.w[0] = t;        /* Block count */
  78.     inreg.eax.w[0] = 0x0007;  // Read file
  79.     inreg.ebx.w[0] = OFFS(__com32.cs_bounce);
  80.     inreg.es = SEG(__com32.cs_bounce);
  81.     printregs(&inreg);
  82.     __com32.cs_intcall(0x22, &inreg, &outreg);
  83.     printregs(&outreg);
  84.     printf("----\n");
  85.     si = outreg.esi.w[0];
  86.  
  87.     /* Print the buffer */
  88.     t = (ax < 65536) ? ax : 65536;
  89.     p = __com32.cs_bounce;
  90.     while ( t ) {
  91.       putchar(*p++);
  92.       t--;
  93.       ax--;
  94.     }
  95.   }
  96.  
  97.   return 0;
  98. }
  99.